package com.info33.platform.business.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.business.app.dto.AppBannerDTO;
import com.info33.platform.business.app.entity.AppBanner;
import com.info33.platform.business.app.service.AppBannerService;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.common.util.SysUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 */
@RestController
@RequestMapping("/AppBanner")
@Api(tags = "app - 轮播图")
public class AppBannerController extends BaseController<AppBannerService, AppBanner> {

    private final AppBannerService appBannerService;

    @Autowired
    public AppBannerController(AppBannerService appBannerService) {
        super(appBannerService);
        this.appBannerService = appBannerService;
    }

    @PostMapping(value = "/pc/list/{pageNum}/{pageSize}")
    @ApiOperation(value = "pc - 分页")
    public Result<IPage<AppBanner>> pcPage(
            @RequestBody AppBannerDTO dto,
            @PathVariable int pageNum,
            @PathVariable int pageSize) {
        return Result.ok(appBannerService.pcBanner(new Page<>(pageNum, pageSize), dto.getType(), getTenantId()));
    }

    @PostMapping(value = "/pc/add")
    @ApiOperation(value = "pc - 添加")
    public Result<Object> pcAdd(
            @RequestBody AppBanner entity) {
        entity.setCommon(SysUtil.isSysAdmin());
        return appBannerService.save(entity) ? Result.ok() : Result.error();
    }

    @PutMapping(value = "/pc/edit")
    @ApiOperation(value = "pc - 编辑")
    public Result<Object> pcEdit(
            @RequestBody AppBanner appBanner) {
        return appBannerService.pcEdit(appBanner);
    }

    @DeleteMapping(value = "/pc/remove/{id}")
    @ApiOperation(value = "pc - 删除")
    public Result<Object> pcRemove(
            @PathVariable(value = "id") Long id) {
        return appBannerService.pcRemove(id);
    }

}